feat: Introduce SidebarItem component to manage sidebar entry colla…
#8150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
clideo_editor_b3a727c65cf5481b997119fdab88f23b.mp4
Overview
This PR enhances the React documentation website's sidebar navigation by allowing users to toggle dropdowns when clicking an already-selected item. This improves overall navigation usability and aligns the behavior with common UI expectations.
Problem Statement
Previously, clicking on an active/selected sidebar item that had a dropdown produced no action.
Users naturally expect that clicking the same selected item again should collapse the dropdown—similar to accordion-style navigation patterns.
This mismatch resulted in:
Solution
A toggle mechanism has been implemented to allow collapsing an expanded dropdown by clicking the currently selected item a second time.
Technical Changes
Modified Files
src/components/Layout/Sidebar/SidebarLink.tsxonClickprop to support custom click behavioronClickhandler down to the underlyingLinkcomponentsrc/components/Layout/Sidebar/SidebarRouteTree.tsxuseStateanduseEffectSidebarItemcomponent to encapsulate item-level logicisCollapsedstate to manage manual expand/collapseisCollapsedwhen clicking on a selected itemuseEffectto resetisCollapsedwhen the item becomes deselectedSidebarItemfor cleaner structureKey Logic
Behavior
Before
After
Benefits
Testing
✅
npm run tsc(TypeScript compilation)✅
npm run lint(ESLint validation)All existing warnings were unrelated to this change
Sidebar Dropdown Should Toggle When Clicking an Already-Selected Item #8149